package zz.extjs.impl;

import java.sql.PreparedStatement;
import java.sql.ResultSet;

import zz.extjs.dao.MemberDAO;
import zz.extjs.dbc.DataBaseConnection;
import zz.extjs.util.MD5;
import zz.extjs.vo.Member;

public class MemberDAOImpl implements MemberDAO {
    public boolean isUser(Member member, String md5oper) throws Exception {
        //设置标志，判断数据库中是否有符合查询条件的记录，true表示有，false表示没有
    	//增加md5oper参数，来自session，与库中密码合并后再经md5加密，与请求密码相同为通过
        boolean is_user=false;
        String sql="Select * FROM user_LOGIN Where u_n=? ";
        PreparedStatement pstmt=null;
        ResultSet rs=null;
        DataBaseConnection dbc=null;
        try{
            dbc=new DataBaseConnection();
            pstmt=dbc.getConnection().prepareStatement(sql);
            pstmt.setString(1, member.getUsername());
            //pstmt.setString(2, member.getPassword());
            rs=pstmt.executeQuery();
            if(rs.next()){
            	MD5 md5 = new MD5();
            	String mm = md5.getMD5ofStr(rs.getString("p_w")+md5oper).toLowerCase();
            	if(mm.equals(member.getPassword()))	//有符合查询条件的记录
            		is_user=true;
            }
            rs.close();
            pstmt.close();
        }
        catch(Exception e){
            throw new Exception("数据库操作失败");
        }
        finally{
            dbc.close();
        }
        return is_user;
    }
}